<?php 
include_once 'plan_func.php';
include_once 'functions.php';
$allBlocks = getAllBlocks();

//incorrect, but for now, I'm leaving it.
$curYear = "2010";

/*categoryname;categoryid!...*/

$categoryNameString = null;
$allCategories = getAllCategories();

for($i = 0; $i<count($allCategories); $i++){
	$categoryNameString = $categoryNameString.$allCategories[$i]['categoryname'].';'.$allCategories[$i]['categoryid'].'!';
}

//echo $categoryNameString;

/*cropname;cropid;catid!...*/

$cropNameString = null;
$allCrops = getAllCrops();
for($i = 0; $i<count($allCrops); $i++){
	$cropNameString = $cropNameString.$allCrops[$i]['cropname'].';'.$allCrops[$i]['cropid'].';'.$allCrops[$i]['categoryid'].'!';
}

$firstCrop = $allCrops[0]['cropid'];

//echo $cropNameString;

/*the string for plan, current year*/
/*
$planString = null;
$planYear = '2010';
$planBlockId = 1;
$planString = getPlan($planBlockId, $planYear);
*/
//echo $planString;


if(isset($_GET['blockid']) && $_GET['blockid']){
    $firstBlock = null;
    foreach($allBlocks as $b){
        if($b['blockid'] == $_GET['blockid']){
            $firstBlock = $b;
            break;
        }
    }
    if($firstBlock == null){
        die("Non-existant block id requested: " . $_GET['blockid']);
    }

    
    
    if(isset($_GET['plan']) && $_GET['plan']){
        addPlan($firstBlock['blockid'], $curYear, $_GET['plan']);
    }

    

}else{
    $firstBlock = $allBlocks[0];
}


$planString = getPlan($firstBlock['blockid'], $curYear);
if($planString == null){
echo "marrow";
    $planString = getEmptyMap($firstBlock['blockid']);
    if($planString == null){
        die("Non-existant block id requested: " . $_GET['blockid']);
    }
}


?>